#include "slepui.h"
#include "cslep.h"
#include "slepbase.h"
#include <QtGui>

void SLEPUI::setupActions(){
	actionExit = new QAction(tr("Exit"),this);
	connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
	actionAddFiles = new QAction(tr("Add File"),this);
	actionChangeCurrentDir = new QAction(tr("Change working directory"),this);
	actionChangeOutputDir = new QAction(tr("Change output directory"),this);
	actionAbout = new QAction(tr("About CSLEP"),this);
	connect(actionAbout,SIGNAL(triggered()),this,SLOT(about()));
	connect(actionChangeCurrentDir,SIGNAL(triggered()),fileTable,SLOT(actChangeCurrentDir()));
	connect(actionChangeOutputDir,SIGNAL(triggered()),fileTable,SLOT(actChangeOutputDir()));
	connect(actionAddFiles, SIGNAL(triggered()), fileTable, SLOT(actAddSomething()));

	actionLeastR = new QAction(tr("Least Squares loss"),this);
	connect(actionLeastR,SIGNAL(triggered()),this,SLOT(actLeastR()));
	actionNnLeastR = new QAction(tr("Least Squares loss (Non-negative Solution)"),this);
	connect(actionNnLeastR,SIGNAL(triggered()),this, SLOT(actnnLeastR()));
	actionLogisticR = new QAction(tr("Logistic loss"),this);
	connect(actionLogisticR, SIGNAL(triggered()), this, SLOT(actLogisticR()));
	actionNnLogisticR = new QAction(tr("Logistic loss (Non-negative Solution)"),this);
	connect(actionNnLogisticR, SIGNAL(triggered()), this, SLOT(actnnLogisticR()));

	actionLeastC = new QAction(tr("Least Squares loss"),this);
	connect(actionLeastC,SIGNAL(triggered()),this, SLOT(actLeastC()));
	actionNnLeastC = new QAction(tr("Least Squares loss (Non-negative Solution)"),this);
	connect(actionNnLeastC,SIGNAL(triggered()),this, SLOT(actnnLeastC()));
	actionLogisticC = new QAction(tr("Logistic loss"),this);
	connect(actionLogisticC,SIGNAL(triggered()),this, SLOT(actLogisticC()));
	actionNnLogisticC = new QAction(tr("Logistic loss (Non-negative Solution)"),this);
	connect(actionNnLogisticC,SIGNAL(triggered()),this, SLOT(actnnLogisticC()));

	actionLq1GlLeastR = new QAction(tr("Group Lasso (Least Squares loss)"),this);
	connect(actionLq1GlLeastR,SIGNAL(triggered()),this, SLOT(actglLeastR()));
	actionLq1GlLogisticR = new QAction(tr("Group Lasso (Logistic loss)"),this);
	connect(actionLq1GlLogisticR, SIGNAL(triggered()),this,SLOT(actglLogisticR()));
	actionLq1McLeastR = new QAction(tr("Multi-class(task) learning (Least Squares loss)"),this);
	actionLq1McLogisticR = new QAction(tr("Multi-class(task) learning (Logistic loss)"),this);
	actionLq1MtLeastR = new QAction(tr("Multi-task learning (Least Squares loss)"),this);
	connect(actionLq1MtLeastR, SIGNAL(triggered()),this,SLOT(actmtLeastR()));
	actionLq1MtLogisticR = new QAction(tr("Multi-task learning (Logistic loss)"),this);
	connect(actionLq1MtLogisticR, SIGNAL(triggered()),this,SLOT(actmtLogisticR()));

	actionL21McLeastC = new QAction(tr("Multi-class(task) learning (Least Squares loss)"),this);
	actionL21McLogisticC = new QAction(tr("Multi-class(task) learning (Logistic loss)"),this);
	actionL21MtLeastC = new QAction(tr("Multi-task learning (Least Squares loss)"),this);
	actionL21MtLogisticC = new QAction(tr("Multi-task learning (Logistic loss)"),this);

	actionFusedLasso = new QAction(tr("Fused Lasso with Least Squares loss"),this);
}


void SLEPUI::setupMenus(){
	menuFile = menuBar()->addMenu(tr("&File"));
	menuFile->addAction(actionAddFiles);
	menuFile->addAction(actionChangeCurrentDir);
	menuFile->addAction(actionChangeOutputDir);
	menuFile->addAction(actionExit);


	menuSolve = menuBar()->addMenu(tr("&Solve"));

	menuSolve->addAction(actionFusedLasso);
	menuL1Regularized = menuSolve->addMenu(tr("L1 Regularized"));
	menuL1Regularized->addAction(actionLeastR);
	menuL1Regularized->addAction(actionNnLeastR);
	menuL1Regularized->addAction(actionLogisticR);
	menuL1Regularized->addAction(actionNnLogisticR);

	menuL1Constrained = menuSolve->addMenu(tr("L1 Constrained"));
	menuL1Constrained->addAction(actionLeastC);
	menuL1Constrained->addAction(actionNnLeastC);
	menuL1Constrained->addAction(actionLogisticC);
	menuL1Constrained->addAction(actionNnLogisticC);

	menuLq1Regularized = menuSolve->addMenu(tr("Lq/L1 Regularized"));
	menuLq1Regularized->addAction(actionLq1GlLeastR);
	menuLq1Regularized->addAction(actionLq1GlLogisticR);
	menuLq1Regularized->addAction(actionLq1McLeastR);
	menuLq1Regularized->addAction(actionLq1McLogisticR);
	menuLq1Regularized->addAction(actionLq1MtLeastR);
	menuLq1Regularized->addAction(actionLq1MtLogisticR);

	menuL21Constrained = menuSolve->addMenu(tr("L2/L1 Constrained"));
	menuL21Constrained->addAction(actionL21McLeastC);
	menuL21Constrained->addAction(actionL21McLogisticC);
	menuL21Constrained->addAction(actionL21MtLeastC);
	menuL21Constrained->addAction(actionL21MtLogisticC);

	menuView = menuBar()->addMenu(tr("&View"));
	menuHelp = menuBar()->addMenu(tr("&Help"));
	menuHelp->addAction(actionAbout);

	menuView->addAction(dockWidget->toggleViewAction());
	menuView->addAction(loggerDock->toggleViewAction());

}



void SLEPUI::setupWorkspacePanel(){
        dockWidget = new QDockWidget(tr("Workspace"),this);
        fileTable = new FileTable(this);
        slepItemList = fileTable->getSlepItemList();
        itemModel = fileTable->getItemModel();
        dockWidget->setWidget(fileTable);
        dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        addDockWidget(Qt::RightDockWidgetArea, dockWidget);
}


void SLEPUI::setupLogger(){
        loggerDock = new QDockWidget(tr("Output Log"),this);
		logger = LogWidget::instance();
        loggerDock->setWidget(logger);
        loggerDock->setAllowedAreas(Qt::BottomDockWidgetArea);
        addDockWidget(Qt::BottomDockWidgetArea, loggerDock);
}